home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #009 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #009 (19xx)(Amiga User Group Deutschland e.V.).adf / Viacom / viacom.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  4KB  |  202 lines

  1. /*  :ts=8 bk=0
  2.  *
  3.  * viacom.c:    Another display hack based on common real-life experience
  4.  *        with Viacom cable service.  Viacom is a registered tradmark
  5.  *        of Viacom Cablevision (probably).
  6.  *
  7.  * Leo L. Schwab            8706.4        (415)-456-6565
  8.  *
  9.  * (-:  Some people accuse me of being sick.  :-)
  10.  * (-:   This should convince any doubters.   :-)
  11.  */
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15. #include <hardware/blit.h>
  16.  
  17. #define MINTERM        ((int) (NABC | ANBC  |  NABNC | ANBNC))
  18. #define    PLUSX        100
  19. #define PLUSY        50
  20.  
  21.  
  22. extern void    *OpenLibrary(), *OpenScreen(), *OpenWindow(), *GetMsg(),
  23.         *AllocRaster(), *CreatePort(), *FindPort();
  24. extern long    VBeamPos();
  25. extern int    rnd();
  26.  
  27. struct NewWindow windef = {
  28.     0, 15, 200, 10,
  29.     -1, -1,
  30.     CLOSEWINDOW,
  31.     WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG | ACTIVATE,
  32.     NULL, NULL,
  33.     (UBYTE *) "Patching in...",
  34.     NULL, NULL,
  35.     0, 0, 0, 0,
  36.     WBENCHSCREEN
  37. };
  38.  
  39. struct Screen    *scr;
  40. struct Window    *win;
  41. struct BitMap    noisemap, phonymap;
  42. struct RastPort    nrp;
  43. struct MsgPort    *flagport;
  44. long        nwide, nhigh;
  45. int        wide, high;
  46. void        *IntuitionBase, *GfxBase;
  47.  
  48. char        *PORTNAME = "Viacom Public Port";
  49.  
  50.  
  51. main ()
  52. {
  53.     register struct Screen *wbs;
  54.     register struct BitMap *wbbm;
  55.     register int i;
  56.     int deep, xoff, yoff;
  57.     int ox[8], oy[8];
  58.     void *msg;
  59.  
  60.     openstuff ();
  61.     rnd ((short) -VBeamPos());
  62.  
  63.     /*  Glean important information from system structures  */
  64.     wbs = win -> WScreen;
  65.     wide = wbs -> Width;
  66.     high = wbs -> Height;
  67.     wbbm = wbs -> ViewPort.RasInfo -> BitMap;
  68.     deep = wbbm -> Depth;
  69.  
  70.     /*  Make the bitplane with the noise in it.  */
  71.     nwide = wide + PLUSX;
  72.     nhigh = high + PLUSY;
  73.     InitBitMap (&noisemap, 1L, nwide, nhigh);
  74.     if (!(noisemap.Planes[0] = AllocRaster (nwide, nhigh)))
  75.         die ("Noise bitmap allocation failed.");
  76.  
  77.     InitRastPort (&nrp);
  78.     nrp.BitMap = &noisemap;
  79.  
  80.     mknoise (nwide, nhigh);
  81.  
  82.     /*  Replace the workbench you see with my phony one.  */
  83.     makephony (wide, high, deep);
  84.     wbs -> ViewPort.RasInfo -> BitMap = &phonymap;
  85.     MakeScreen (wbs);
  86.     RethinkDisplay ();
  87.     SetWindowTitles (win, "\273> Viacom <\253", "Viacom Cablevision");
  88.  
  89.     while (1) {
  90.         if (msg = GetMsg (win -> UserPort)) {
  91.             ReplyMsg (msg);
  92.             break;
  93.         }
  94.  
  95.         OwnBlitter ();
  96.         for (i=0; i<deep; i++) {
  97.             while (abs ((xoff = rnd (PLUSX)) - ox[i]) < 10)
  98.                 ;
  99.             while (abs ((yoff = rnd (PLUSY)) - oy[i]) < 10)
  100.                 ;
  101.  
  102.             oddblit (wbbm -> Planes[i], phonymap.Planes[i],
  103.                  wide, high,
  104.                  noisemap.Planes[0],
  105.                  (int) nwide, (int) nhigh,
  106.                  xoff, yoff, MINTERM);
  107.  
  108.             ox[i] = xoff;  oy[i] = yoff;
  109.         }
  110.         DisownBlitter ();
  111.         WaitTOF ();
  112.     }
  113.  
  114.     /*  Return to normal  */
  115.     wbs -> ViewPort.RasInfo -> BitMap = wbbm;
  116.     MakeScreen (wbs);
  117.     RethinkDisplay ();
  118.     closestuff ();
  119. }
  120.  
  121. mknoise (wide, high)
  122. long wide, high;
  123. {
  124.     register unsigned int x, i;
  125.  
  126.     SetRast (&nrp, 0L);
  127.     SetDrMd (&nrp, COMPLEMENT);
  128.  
  129.     for (x=0; x<wide; x++)
  130.         for (i=0; i<20; i++)
  131.             WritePixel
  132.              (&nrp, (long) x, (long) rnd ((short) high));
  133. }
  134.  
  135. abs (x)
  136. int x;
  137. {
  138.     return (x < 0 ? -x : x);
  139. }
  140.  
  141. makephony (wide, high, deep)
  142. int wide, high, deep;
  143. {
  144.     InitBitMap (&phonymap, (long) deep, (long) wide, (long) high);
  145.  
  146.     while (deep--)    /*  deep decremented after test  */
  147.         if (!(phonymap.Planes[deep] = AllocRaster
  148.                            ((long) wide, (long) high)))
  149.             die ("Couldn't allocate clone bitmap.");
  150. }
  151.  
  152. openstuff ()
  153. {
  154.     /*
  155.      * Running Viacom multiple times at once could really muck things
  156.      * up, especially if you exit them in the wrong order.  So we do
  157.      * this so that only one Viacom process is active at any given time.
  158.      */
  159.     if (FindPort (PORTNAME))
  160.         die ("You are already connected to Viacom.");
  161.     else
  162.         flagport = CreatePort (PORTNAME, NULL);
  163.  
  164.     initblitdata ();
  165.  
  166.     if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L)))
  167.         die ("-=RJ=- is on vacation.");
  168.  
  169.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L)))
  170.         die ("Dale?  Are you there?");
  171.  
  172.     if (!(win = OpenWindow (&windef)))
  173.         die ("Window painted shut.");
  174. }
  175.  
  176. closestuff ()
  177. {
  178.     register int i;
  179.  
  180.     for (i=0; i<phonymap.Depth; i++)
  181.         if (phonymap.Planes[i])
  182.             FreeRaster
  183.              (phonymap.Planes[i], (long) wide, (long) high);
  184.  
  185.     if (noisemap.Planes[0])
  186.         FreeRaster (noisemap.Planes[0], nwide, nhigh);
  187.  
  188.     if (win)        CloseWindow (win);
  189.     if (scr)        CloseScreen (scr);
  190.     if (GfxBase)        CloseLibrary (GfxBase);
  191.     if (IntuitionBase)    CloseLibrary (IntuitionBase);
  192.     if (flagport)        DeletePort (flagport);
  193. }
  194.  
  195. die (str)
  196. char *str;
  197. {
  198.     puts (str);
  199.     closestuff ();
  200.     exit (20);
  201. }
  202.